package com.fxsh168.server.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ListView;

import com.fxsh168.server.R;
import com.fxsh168.server.adapters.MyTwoAdapter;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.entitys.MyTwoEntity;
import com.fxsh168.server.interfaces.Constant;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import okhttp3.Call;


public class MyThreeFenActivity extends BaseActivity {
    ListView lstMyThree;
    MyTwoAdapter myTwoAdapter;
    List<String> data;
    private String mPhone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_three);
        lstMyThree = (ListView) findViewById(R.id.lstMyThree);
        SharedPreferences sp = getSharedPreferences(Constant.LOGINCLASS, MODE_PRIVATE);
        mPhone = sp.getString("mPhone", "");
        getThree();
    }

    //   三级
    public void getThree() {
        OkHttpUtils.post().url(Constant.MYTHREE).addParams("phone", mPhone).addParams("type", "2").build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("tag", " 我的三级数据获取失败的原因 " + e);

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("tag", " 我的三级数据获取 " + response);
                        MyTwoEntity myTwoEntity = new Gson().fromJson(response, MyTwoEntity.class);
                        String code = myTwoEntity.getCode();
                        if (code.equals("200")) {
                            data = myTwoEntity.getData();
                            myTwoAdapter = new MyTwoAdapter(data, MyThreeFenActivity.this);
                            lstMyThree.setAdapter(myTwoAdapter);
                        }
                    }
                });

    }


}
